// css文件 loader配置

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { isDev } = require("../env");
const { customAntdTheme } = require("../antd-theme");

const getStyleLoaders = (preProcessor) => {
  return [
    isDev ? "style-loader" : MiniCssExtractPlugin.loader,
    "css-loader",
    "postcss-loader",
    preProcessor && {
      loader: preProcessor,
      options:
        preProcessor === "less-loader"
          ? {
            // antd的自定义主题
            lessOptions: {
              modifyVars: customAntdTheme,
              javascriptEnabled: true,
            },
          }
          : {},
    },
  ].filter(Boolean);
};


module.exports = [{
  test: /\.css$/,
  exclude: /node_modules/,
  use: getStyleLoaders(),
},
{
  // 处理项目中的less文件
  test: /\.less$/,
  use: getStyleLoaders("less-loader"),
},
{
  test: /\.s[ac]ss$/,
  use: getStyleLoaders("sass-loader"),
}]
